/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:      etherifopt.c
**  Author:  Michael
**  Date:    06/27/2014
**
**  Purpose:
**    ether interface method implement.
*/

/* Include files. */

#include "dpmgr.h"
#include "osdep.h"
#include "pfdep.h"
#include "etherifopt.h"

/* Macro constant definitions. */

/* Type definitions. */

/* Local function declarations. */

static e_ret ether_if_create(tdp_if * dp_if);
static e_ret ether_if_destroy(tdp_if * dp_if);
static e_ret ether_if_enable(tdp_if * dp_if);
static e_ret ether_if_disable(tdp_if * dp_if);
static e_ret ether_if_setlinkcfg(tdp_if * dp_if, void *linkcfg, tmask * mask);
static e_ret ether_if_link(tdp_if * dp_if);
static e_ret ether_if_unlink(tdp_if * dp_if);
static e_ret ether_if_collectlinkstat(tdp_if * dp_if);
static e_ret ether_if_getlinkstat(tdp_if * dp_if, void **linkstat, int *size, tmask * mask);
static e_ret ether_if_getlinkstatus(tdp_if * dp_if, void **status, int *size, tmask * mask);
static e_ret ether_if_setnetcfg(tdp_if * dp_if, void *netcfg, tmask * mask);
static e_ret ether_if_connect(tdp_if * dp_if);
static e_ret ether_if_disconnect(tdp_if * dp_if);
static e_ret ether_if_collectnetstat(tdp_if * dp_if);
static e_ret ether_if_getnetstat(tdp_if * dp_if, void **netstat, int *size, tmask * mask);
static e_ret ether_if_getnetstatus(tdp_if * dp_if, void **status, int *size, tmask * mask);

/* Macro API definitions. */

/* Global variable declarations. */

e_ret ether_if_prepare(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	dp_if->create = ether_if_create;
	dp_if->destroy = ether_if_destroy;
	dp_if->enable = ether_if_enable;
	dp_if->disable = ether_if_disable;
	dp_if->setlinkcfg = ether_if_setlinkcfg;
	dp_if->getlinkcfg = dpif_getlinkcfg_common;
	dp_if->link = ether_if_link;
	dp_if->unlink = ether_if_unlink;
	dp_if->collectlinkstat = ether_if_collectlinkstat;
	dp_if->getlinkstat = ether_if_getlinkstat;
	dp_if->getlinkstatus = ether_if_getlinkstatus;
	dp_if->setnetcfg = ether_if_setnetcfg;
	dp_if->getnetcfg = dpif_getnetcfg_common;
	dp_if->connect = ether_if_connect;
	dp_if->disconnect = ether_if_disconnect;
	dp_if->collectnetstat = ether_if_collectnetstat;
	dp_if->getnetstat = ether_if_getnetstat;
	dp_if->getnetstatus = ether_if_getnetstatus;

	sysmgr_trace_exit();
	return (eRET_SUCCESS);

}

e_ret ether_if_create(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_destroy(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_enable(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (os_dep_if_up(dp_if->name));
}

e_ret ether_if_disable(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (os_dep_if_down(dp_if->name));
}

e_ret ether_if_setlinkcfg(tdp_if * dp_if, void *linkcfg, tmask * mask)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_link(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_unlink(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_collectlinkstat(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_getlinkstat(tdp_if * dp_if, void **linkstat, int *size, tmask * mask)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_getlinkstatus(tdp_if * dp_if, void **status, int *size, tmask * mask)
{

	e_ret ret = eRET_SUCCESS;
	teth_if_link_status *link_status;

	sysmgr_trace_enter();

	ret = pf_dep_ether_get_linkstatus(dp_if, &link_status);
	if (ret != eRET_SUCCESS) {
		*size = 0;
		*status = NULL;
	} else {
		if (link_status != NULL) {
			*status = link_status;
			*size = sizeof(*link_status);
		} else {
			*status = NULL;
			*size = 0;
		}
	}

	sysmgr_trace_exit();
	return (ret);
}

e_ret ether_if_setnetcfg(tdp_if * dp_if, void *netcfg, tmask * mask)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_connect(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_disconnect(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_collectnetstat(tdp_if * dp_if)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_getnetstat(tdp_if * dp_if, void **netstat, int *size, tmask * mask)
{
	sysmgr_trace_enter();

	sysmgr_trace_exit();
	return (eRET_SUCCESS);
}

e_ret ether_if_getnetstatus(tdp_if * dp_if, void **status, int *size, tmask * mask)
{
	e_ret ret;

	sysmgr_trace_enter();

	ret = dpif_getnetstatus_common(dp_if, (void *)status, size);

	sysmgr_trace_exit();
	return (ret);
}
